package com.xdqzy.baseline.common.config;

import com.xdqzy.baseline.common.utils.CommonUtils;
import com.xdqzy.baseline.common.utils.DateUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties("custom.server")
public class ServerConfigProperties {
    private String fileUpload;

    private String staticPrefix;

    private String serverPrefix;

    public String getFileUpload() {
        return fileUpload;
    }

    public void setFileUpload(String fileUpload) {
        this.fileUpload = fileUpload;
    }

    public String getStaticPrefix() {
        return staticPrefix;
    }

    public void setStaticPrefix(String staticPrefix) {
        this.staticPrefix = staticPrefix;
    }

    public String getServerPrefix() {
        return serverPrefix;
    }

    public void setServerPrefix(String serverPrefix) {
        this.serverPrefix = serverPrefix;
    }

    public String buildRandomFilePath(String uploadDir, String type) {
        String fileName = DateUtils.getNowShortTime() + "_" + CommonUtils.buildRandomCode() + type;
        return fileUpload + uploadDir + fileName;
    }

    public String buildFileUrl(String uploadDir, String fileName) {
        return staticPrefix + uploadDir + fileName;
    }

}
